use "JLC_Replication.dta", clear

replace represents=. if represents==-1
gen repD=.
replace repD=1 if represents==1|represents==2
replace repD=0 if represents==3|represents==4

gen difSplit=.
replace difSplit=2 if difference==4|difference==3|difference==2|difference==1
replace difSplit=0 if difference==-4|difference==-3|difference==-2|difference==-1
replace difSplit=1 if difference==0
gen sclib1=.
replace sclib1=0 if sclib==1
replace sclib1=1 if sclib==3
replace sclib1=2 if sclib==2
gen aboutright = .
replace aboutright = 1 if sclib==3
replace aboutright = 0 if sclib==1|sclib==2
replace aboutright = 0 if sclib==1|sclib==2

gen bj=.
replace bj=1 if condition==1
replace bj=1 if condition==3
replace bj=0 if condition==2
replace bj=0 if condition==4
gen repreflect = 5-represents
gen absdiff = abs(difference)
gen difference1 = (difference+4)/8
gen absdiff1 = absdiff/4

generate differencetext=""
replace differencetext="a great deal more liberal than you are" if difference==-4|difference==-3
replace differencetext="somewhat more liberal than you are" if difference==-2|difference==-1
replace differencetext="holding similar views to you" if difference==0
replace differencetext="somewhat more conservative than you are" if difference==1|difference==2
replace differencetext="a great deal more conservative than you are" if difference==4|difference==3


*generate insample
reg repreflect difference REALISM3X scknow PARTYID2 AGE2 gender black hispanic EDUC3 ownhome ATTEND2 [aw=NW]
gen insample=1 if e(sample)==1


*Table 1
ologit repreflect c.difference##c.REALISM3X scknow PARTYID2 AGE2 gender black hispanic EDUC3 ownhome ATTEND2 [aw=NW]

*Table B1 (And Figure 1; R Code makes the plots)
**Model 1
reg sclib1 c.difference##c.REALISM3X scjob scknow PARTYID2 AGE2 gender black hispanic EDUC3 ownhome ATTEND2 [aw=NW] if represents==1
estimates store r1
predict p1 if e(sample)==1
gen e1 = (sclib1-p1)^2 if e(sample)==1
summarize e1

**Model 2
reg sclib1 c.difference##c.REALISM3X scjob scknow PARTYID2 AGE2 gender black hispanic EDUC3 ownhome ATTEND2 [aw=NW] if represents==2
estimates store r2
predict p2 if e(sample)==1
gen e2 = (sclib1-p2)^2 if e(sample)==1
summarize e2

**Model 3
reg sclib1 c.difference##c.REALISM3X scjob scknow PARTYID2 AGE2 gender black hispanic EDUC3 ownhome ATTEND2 [aw=NW] if represents==3
estimates store r3
predict p3 if e(sample)==1
gen e3 = (sclib1-p3)^2 if e(sample)==1
summarize e3

**Model 4
reg sclib1 c.difference##c.REALISM3X scjob scknow PARTYID2 AGE2 gender black hispanic EDUC3 ownhome ATTEND2 [aw=NW] if represents==4
estimates store r4
predict p4 if e(sample)==1
gen e4 = (sclib1-p4)^2 if e(sample)==1
summarize e4

*Table B2
*Model 1
drop p1-p3 
ologit sclib1 c.difference##c.REALISM3X scjob scknow PARTYID2 AGE2 gender black hispanic EDUC3 ownhome ATTEND2 [aw=NW] if represents==1
estimates store r1
predict p1 p2 p3 if represents==1
egen maxpred = rowmax(p1-p3)
gen vpred = .
forval i = 1/3 {
replace vpred = `i' if p`i' == maxpred & represents==1
}
tab2 sclib1 vpred, chi2 matcell(t)
display trace(t)/r(N)
drop p1-p3 maxpred vpred

*Model 2
ologit sclib1 c.difference##c.REALISM3X scjob scknow PARTYID2 AGE2 gender black hispanic EDUC3 ownhome ATTEND2 [aw=NW] if represents==2
estimates store r2
predict p1 p2 p3 if represents==2
egen maxpred = rowmax(p1-p3)
gen vpred = .
forval i = 1/3 {
replace vpred = `i' if p`i' == maxpred & represents==2
}
tab2 sclib1 vpred, chi2 matcell(t)
display trace(t)/r(N)
drop p1-p3 maxpred vpred

*Model 3
ologit sclib1 c.difference##c.REALISM3X scjob scknow PARTYID2 AGE2 gender black hispanic EDUC3 ownhome ATTEND2 [aw=NW] if represents==3
estimates store r3
predict p1 p2 p3 if represents==3
egen maxpred = rowmax(p1-p3)
gen vpred = .
forval i = 1/3 {
replace vpred = `i' if p`i' == maxpred & represents==3
}
tab2 sclib1 vpred, chi2 matcell(t)
display trace(t)/r(N)
drop p1-p3 maxpred vpred

*Model 4
ologit sclib1 c.difference##c.REALISM3X scjob scknow PARTYID2 AGE2 gender black hispanic EDUC3 ownhome ATTEND2 [aw=NW] if represents==4
estimates store r4
predict p1 p2 p3 if represents==4
egen maxpred = rowmax(p1-p3)
gen vpred = .
forval i = 1/3 {
replace vpred = `i' if p`i' == maxpred & represents==4
}
tab2 sclib1 vpred, chi2 matcell(t)
display trace(t)/r(N)
drop p1-p3 maxpred vpred


*Table B3 (And Figures 2 and 3; R Code makes the plots)
reg scsupx c.repreflect##c.IDEODIF0 [aw=NW]
estimates store m1
margins, dydx(IDEODIF0) at(repreflect=(1 2 3 4))
reg scsupx c.repreflect##c.IDEODIF5SQ [aw=NW]
estimates store m2
margins, dydx(IDEODIF5SQ) at(repreflect=(1 2 3 4))
gen IDEODIF7ABS = sqrt(IDEODIF7SQ)
reg scsupx c.repreflect##c.IDEODIF7ABS [aw=NW]
estimates store m7
margins, dydx(IDEODIF7ABS) at(repreflect=(1 2 3 4))
gen IDEODIF1ABS = sqrt(IDEODIF1SQ)
gen IDEODIF3ABS = sqrt(IDEODIF3SQ)
reg scsupx c.repreflect##c.IDEODIF1ABS [aw=NW]
estimates store m3
margins, dydx(IDEODIF1ABS) at(repreflect=(1 2 3 4))
reg scsupx c.repreflect##c.IDEODIF3ABS [aw=NW]
estimates store m4
margins, dydx(IDEODIF3ABS) at(repreflect=(1 2 3 4))
reg scsupx c.repreflect##c.absdiff1 [aw=NW]
estimates store m5
margins, dydx(absdiff1) at(repreflect=(1 2 3 4))


